<?php
set_include_path(implode(PATH_SEPARATOR, array(
				realpath(dirname(__FILE__) . '/../library'),
				'.',
		  )));

// Define path to application directory
defined('APPLICATION_PATH')
		  || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
		  || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

try
{
	require_once 'Zend/Config/Ini.php';
	$options = new Zend_Config_Ini(APPLICATION_PATH . '/config/application.ini', APPLICATION_ENV, true);

	$config = new Zend_Config_Ini(APPLICATION_PATH . '/config/config.ini', APPLICATION_ENV);
	$options->merge($config);
	$options->setReadOnly();

	/** Zend_Application */
	require_once 'Zend/Application.php';

	// Create application, bootstrap, and run
	$application = new Zend_Application(
						 APPLICATION_ENV,
						 $options
	);

	$application->bootstrap();
	$application->run();
} catch (Exception $exception)
{
	?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<title>An exception occurred while bootstrapping the application</title>
		</head>
		<body>
			<p align="center">
				An exception occurred while bootstrapping the application
			</p>

			<?php if (defined('APPLICATION_ENV') && APPLICATION_ENV != 'production'): ?>
				<p align="center">
					<?php echo $exception->getMessage(); ?>
				</p>

				<div align="left">
					Stack Trace:
					<pre><?php echo $exception->getTraceAsString(); ?></pre>
				</div>
			<?php endif; ?>
		</body>
	</html>
	<?php
	exit(1);
}